package com.sun.hunk.hibernate.domain.impl;

import com.sun.hunk.hibernate.domain.GenericCode;
import com.sun.hunk.hibernate.domain.Item;
import com.sun.hunk.hibernate.domain.ItemCharge;
import com.sun.hunk.hibernate.domain.Payment;
import com.sun.hunk.hibernate.domain.Purchase;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author sunil
 */
@Entity
@Table(name = "purchase")
public class PurchaseImpl implements Purchase {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Column(name = "quantity")
    private Integer quantity;
    @Column(name = "amount")
    private Double amount;
    @Column(name = "return_quantity")
    private Integer returnQantity;
    @Column(name = "purchase_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date purchaseDate;
    @Column(name = "purchase_from")
    private String purchaseFrom;
    @Column(name = "weight")
    private Double weight;
    @Column(name = "size_h")
    private Integer sizeH;
    @Column(name = "size_w")
    private Integer sizeW;
    @Column(name = "size_l")
    private Integer sizeL;
    @Column(name = "size_unit")
    private String sizeUnit;
    @Column(name = "remarks")
    private String remarks;
    @OneToMany(mappedBy = "purchase",targetEntity=ItemChargeImpl.class, cascade=CascadeType.ALL)
    private List<ItemCharge> charges = new ArrayList<ItemCharge>();
    @JoinColumn(name = "payment_id", referencedColumnName = "id")
    @OneToOne(targetEntity=PaymentImpl.class, cascade=CascadeType.ALL)
    private Payment payment;
    @JoinColumn(name = "item_id", referencedColumnName = "id")
    @ManyToOne(targetEntity=ItemImpl.class)
    private Item item;
    @JoinColumn(name = "payment_mode_id", referencedColumnName = "id")
    @ManyToOne(targetEntity=GenericCodeImpl.class, cascade=CascadeType.ALL)
    private GenericCode paymentMode;

    public PurchaseImpl() {
        date = new Date();
    }

    public PurchaseImpl(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public Integer getReturnQantity() {
        return returnQantity;
    }

    public void setReturnQantity(Integer returnQantity) {
        this.returnQantity = returnQantity;
    }
    
    public Date getPurchaseDate() {
        return purchaseDate;
    }

    public void setPurchaseDate(Date purchaseDate) {
        this.purchaseDate = purchaseDate;
    }

    public String getPurchaseFrom() {
        return purchaseFrom;
    }

    public void setPurchaseFrom(String purchaseFrom) {
        this.purchaseFrom = purchaseFrom;
    }

    public Double getWeight() {
        return weight;
    }

    public void setWeight(Double weight) {
        this.weight = weight;
    }

    public Integer getSizeH() {
        return sizeH;
    }

    public void setSizeH(Integer sizeH) {
        this.sizeH = sizeH;
    }

    public Integer getSizeW() {
        return sizeW;
    }

    public void setSizeW(Integer sizeW) {
        this.sizeW = sizeW;
    }

    public Integer getSizeL() {
        return sizeL;
    }

    public void setSizeL(Integer sizeL) {
        this.sizeL = sizeL;
    }

    public String getSizeUnit() {
        return sizeUnit;
    }

    public void setSizeUnit(String sizeUnit) {
        this.sizeUnit = sizeUnit;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public List<ItemCharge> getCharges() {
        return charges;
    }

    public void setCharges(List<ItemCharge> charges) {
        this.charges = charges;
    }

    public GenericCode getPaymentMode() {
        return paymentMode;
    }

    public void setPaymentMode(GenericCode paymentMode) {
        this.paymentMode = paymentMode;
    }

    public Payment getPayment() {
        return payment;
    }

    public void setPayment(Payment payment) {
        this.payment = payment;
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }


    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PurchaseImpl)) {
            return false;
        }
        PurchaseImpl other = (PurchaseImpl) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.sun.hunk.hibernate.domain.Purchase[id=" + id + "]";
    }

}
